package com.zpkj.portal.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

@Component
public class IpInterceptor implements HandlerInterceptor{

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		/*
		String ip = request.getRemoteAddr();
		RedisService redisService = BeanFactoryUtils.getBean("redisService");
		String redisValue = redisService.getRedisValue(ip);
    	if(StringUtil.isNotEmpty(redisValue)){
    		if(Integer.valueOf(redisValue)>5000){
    			redisService.expire(ip, 3600*24);
    			return false;
    		}else{
    			redisService.setRedisValue(ip, Integer.toString(Integer.valueOf(redisValue)+1),700);
    		}
			redisService.setRedisValue(ip, Integer.toString(Integer.valueOf(redisValue)+1),700);
    	}else{
			redisService.setRedisValue(ip, "1",700);
    	}
    	*/
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
	}

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
	}

}
